extends Node

var utils = null
var ctrl = null
var gBattle
var gsell
var diff
var base = null
var path = null
var window
var charaBuildBonus = 0
var shieldBonus = 1
var uiNode
var alllist = []
var blist = []
var nlist = []
func _ready():
	pass
func _init():
	call_deferred("init")
func _connect():
	pass
#初始化
func init():
	if globalData.infoDs.has("g_AneHekBase"):
		base = globalData.infoDs["g_AneHekBase"]
		path = chaData.infoDs["cTDW"].dir
	if base != null:
		#初始化
		utils = globalData.infoDs["g_AneHekUtils"]
		ctrl = globalData.infoDs["g_AneHek"]
		gsell = globalData.infoDs["g_AneHekSell"]
		base.connect("onStartGame",self,"createBuffBtn")
		base.connect("onLoadGame",self,"loaddata")#继续游戏
		base.connect("onNewGame",self,"resetdata")#开一局新游戏
		base.connect("onSaveGame",self,"backTitle")#返回标题（保存）
		#azurCtrl.connect("initMainUI", self, "initBonus")
		#diff = globalData.infoDs["g_AneHekDifficult"]
		#shop = globalData.infoDs["g_AneHekShop"]
		#research = globalData.infoDs["g_AneHekResearch"]

func createBuffBtn():
	if !ctrl.allflag || window || !base.getSetting("servoMode",true):return
	uiNode = sys.main.get_node("ui")
	
	pass

func backTitle():
	base.setData("blist",blist)
	base.setData("nlist",nlist)

func resetdata():
	if is_instance_valid(window):
		window.queue_free()
		window = null
	charaBuildBonus = 0
	shieldBonus = 1
	blist = []
	nlist = []

func loaddata():
	resetdata()
	blist = base.getData("blist",[])
	nlist = base.getData("nlist",[])
	if nlist.size():
		for i in nlist:
			call_deferred(i.fname)

func confirmServo(servo):
	if servo.type == "n":
		nlist.append(servo)
		call_deferred(servo.fname)
	else:
		blist.append(servo)
		
#————————————————————————NULL————————————————————————#链接函数，待完善
func n1():#商店刷新场数减少5场，但物品价格上升100金币
	gsell.cnt = 5
	gsell.pr1 = 150
	gsell.pr2 = 167
	gsell.pr3 = 350
func n2():#一发的价格上升30，但高品质概率+4%
	utils.pr = 1
	charaBuildBonus += 0.04
func n3():#一发的价格下降50，但高品质概率-4%
	utils.pr = 1
	charaBuildBonus -= 0.04
#所有附加护盾值附加时，额外增加12%，但护盾受到伤害时增加8%伤害
#材料出售价格增加10金币，材料获得概率降低2%
#人物材料无法出售，装备材料获得概率+10%
#人物材料获得翻倍，但升级需要的特定材料（除了神发）翻倍
#人物等级上限增加5，但每级增加属性降低（生命-30，攻击-7，防御-3）
#英雄等级上限+7，但所需经验增加
#————————————————————————BattleStart————————————————————————#人物id关键词，buff
#各种人物的变量
class bf1 extends Buff:#对所有远程敌人（3格及其以上）伤害增加20%，但受到其伤害增加13%
	var canremove:bool = false
	func _init(lv):
		attInit()
		id = "bf1"

	func _connect():
		masCha.connect("onHurt",self,"dmg1")
		masCha.connect("onAtkChara",self,"dmg2")

	func dmg1(atkinfo):
		if atkinfo.atkCha.att.atkRan > 2 && atkinfo.atkCha.team != masCha.team:
			atkinfo.hurtVal *= 1.13

	func dmg2(atkinfo):
		if atkinfo.hitCha.att.atkRan > 2 && atkinfo.hitCha.team != masCha.team:
			atkinfo.hurtVal *= 1.2

class bf2 extends Buff:#穿透+20;对所有近战敌人（1-2格）伤害增加10%，但受到其伤害增加10%
	var canremove:bool = false
	func _init(lv):
		attInit()
		id = "bf2"
		att.pen = 20
		att.mgiPen = 20
		
	func _connect():
		masCha.connect("onHurt",self,"dmg1")
		masCha.connect("onAtkChara",self,"dmg2")

	func dmg1(atkinfo):
		if atkinfo.atkCha.att.atkRan < 3 && atkinfo.atkCha.team != masCha.team:
			atkinfo.hurtVal *= 1.1

	func dmg2(atkinfo):
		if atkinfo.hitCha.att.atkRan < 3 && atkinfo.hitCha.team != masCha.team:
			atkinfo.hurtVal *= 1.1

class bf3 extends Buff:#对所有敌人伤害增加20%，但攻速减少66%
	var canremove:bool = false
	func _init(lv):
		attInit()
		id = "bf2"
		att.atkR = 0.2
		att.spd = -0.66

class bf4 extends Buff:#开局对全体敌方附加2s眩晕，但开局5秒受到伤害增加10%
	var canremove:bool = false
	var ctrl = globalData.infoDs["g_AneHek"]
	func _init(lv):
		attInit()
		id = "bf4"
		life = 5.0
		att.defR = -0.1
	
	func _connect():
		var chas = masCha.getAllChas(1)
		var chas2 = masCha.getAllChas(2)
		var val = 1.0 / chas2.size()
		for i in chas:
			i.addBuff(ctrl.b_xuanyun.new(val))

class bf5 extends Buff:#射手系伤害增加20%，攻速降低50%
	var canremove:bool = false
	var ctrl = globalData.infoDs["g_AneHek"]
	func _init(lv):
		attInit()
		id = "bf5"
		att.atkR = 0.2
		att.spd = -0.5
	
	func _connect():
		if masCha.get("camp") != "射手":
			isDel = true

class bf6 extends Buff:#战士系攻速增加66%，攻击降低30%
	var canremove:bool = false
	var ctrl = globalData.infoDs["g_AneHek"]
	func _init(lv):
		attInit()
		id = "bf6"
		att.atkL = -0.3
		att.spd = 0.66
	
	func _connect():
		if masCha.get("camp") != "战士":
			isDel = true

class bf7 extends Buff:#刺客系暴击增加10%，生命降低10%
	var canremove:bool = false
	var ctrl = globalData.infoDs["g_AneHek"]
	func _init(lv):
		attInit()
		id = "bf7"
		att.maxHpL = -0.1
		att.cri = 0.1
	
	func _connect():
		if masCha.get("camp") != "刺客":
			isDel = true

class bf8 extends Buff:#软泥怪系生命增加20%，护甲降低30
	var canremove:bool = false
	var ctrl = globalData.infoDs["g_AneHek"]
	func _init(lv):
		attInit()
		id = "bf8"
		att.maxHpL = 0.2
		att.def = -30
		att.mgiDef = -30
	
	func _connect():
		if masCha.get("camp") != "软泥怪":
			isDel = true

class bf9 extends Buff:#牧师系攻击增加20%，生命降低20%
	var canremove:bool = false
	var ctrl = globalData.infoDs["g_AneHek"]
	func _init(lv):
		attInit()
		id = "bf9"
		att.maxHpL = -0.2
		att.atkL = 0.2
	
	func _connect():
		if masCha.get("camp") != "牧师":
			isDel = true

class bf10 extends Buff:#娜迦系冷却减少20%，生命降低10%
	var canremove:bool = false
	var ctrl = globalData.infoDs["g_AneHek"]
	func _init(lv):
		attInit()
		id = "bf10"
		att.maxHpL = -0.1
		att.cd = 0.2
	
	func _connect():
		if masCha.get("camp") != "娜迦":
			isDel = true

class bf11 extends Buff:#骷髅系护甲增加50，生命降低10%
	var canremove:bool = false
	var ctrl = globalData.infoDs["g_AneHek"]
	func _init(lv):
		attInit()
		id = "bf11"
		att.maxHpL = -0.1
		att.def = 50
		att.mgiDef = 50
	
	func _connect():
		if masCha.get("camp") != "骷髅":
			isDel = true

class bf12 extends Buff:#蟹族系减伤增加13%，生命降低23%
	var canremove:bool = false
	var ctrl = globalData.infoDs["g_AneHek"]
	func _init(lv):
		attInit()
		id = "bf12"
		att.maxHpL = -0.23
		att.defR = 0.13
	
	func _connect():
		if masCha.get("camp") != "蟹族":
			isDel = true

class bf13 extends Buff:#所有近战(攻击范围1~2)有10%概率反击敌人，造成<自身生命上限3%>的真伤，但承受伤害-7%
	var canremove:bool = false
	var ctrl = globalData.infoDs["g_AneHek"]
	func _init(lv):
		attInit()
		id = "bf13"
		att.defR = -0.07
	
	func _connect():
		if masCha.att.atkRan < 3:
			masCha.connect("onHurt",self,"returndmg")
		else:
			isDel = true
	
	func returndmg(atkinfo):
		if !atkinfo.isMiss || !atkinfo.atkCha :return
		if sys.rndPer(10):
			masCha.hurtChara(atkinfo.atkCha,masCha.att.maxHp * 0.03,Chara.HurtType.REAL,Chara.AtkType.EFF) 



